<?php

class AdminController extends Controller
{
    private $_identity;
    
	/**
	 * This is the administration page.
	 */
	public function actionIndex()
	{
        if(Yii::app()->user->isAdmin())
            $this->render('index');
        else
            $this->redirect(Yii::app()->homeUrl);
	}

	public function actionProjects()
	{
        if(Yii::app()->user->isAdmin())
        {
            $model=new Project;
            $this->render('projects',array('model'=>$model));
        }
        else
            $this->redirect(Yii::app()->homeUrl);
	}

	public function actionInformations()
	{
        
        if(Yii::app()->user->isAdmin())
        {
            $this->_identity=new UserIdentity('admin','admin');
			$this->_identity->authenticate();
            $defaultAdminAccountChanged = !($this->_identity->errorCode===UserIdentity::ERROR_NONE);
            // TODO : implement verification for hereunder informations
            $fileRepositoryWritable = 1;
            $pluginAssetsWritable = 1;
            $rmagickAvailable = 1;
            // List of informations with following details : label, required or not, verification result
            $informations=array(
                array(
                    Yii::t('admin','Default administrator account changed'),
                    false,
                    $defaultAdminAccountChanged
                ),
                array(
                    Yii::t('admin','Attachments directory writable'),
                    false,
                    $fileRepositoryWritable
                ),
                array(
                    Yii::t('admin','Plugin assets directory writable'),
                    false,
                    $pluginAssetsWritable
                ),
                array(
                    Yii::t('admin','RMagick available (optional)'),
                    false,
                    $rmagickAvailable
                ),
            );
            $this->render('informations',array('informations'=>$informations));
        }
        else
            $this->redirect(Yii::app()->homeUrl);
	}

	// Uncomment the following methods and override them if needed
	/*
	public function filters()
	{
		// return the filter configuration for this controller, e.g.:
		return array(
			'inlineFilterName',
			array(
				'class'=>'path.to.FilterClass',
				'propertyName'=>'propertyValue',
			),
		);
	}

	public function actions()
	{
		// return external action classes, e.g.:
		return array(
			'action1'=>'path.to.ActionClass',
			'action2'=>array(
				'class'=>'path.to.AnotherActionClass',
				'propertyName'=>'propertyValue',
			),
		);
	}
	*/
}